﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TccServicos.Models;
using TccServicos.Util;

namespace TccServicos.Controllers
{
    public class NotificacaoController : ApiController
    {
        private string sThread = "";

        [HttpPost]
        public RetornoServico EnviaNotificacao(NotificacaoPayload notificacao)
        {
            sThread = Util.Util.NextHex(4);
            string nomeFuncao = string.Format("{0} [{1}]", "EnviaNotificacao", sThread);

            try
            {
                Negocio.Notificacao notification = new Negocio.Notificacao();
                notification.SendNotification(notificacao.token, notificacao.mensagem);
                return Util.Util.RetornoOk();
            }
            catch (Exception ex)
            {
                Log.GravarLog(string.Format("{0} Erro: {1}", nomeFuncao, ex.ToString()));
                return Util.Util.RetornoErro(ex.ToString());
            }
        }
    }
}
